package com.oa.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Author: 一拳超人
 * @Date: 2021/10/21 19:34
 */
@Configuration
@EnableOpenApi
public class Swagger2Config implements WebMvcConfigurer {
    @Bean
    public Docket docket1() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.oa.controller.admin"))
                .paths(PathSelectors.any())
                .build().groupName("admin");
    }

    @Bean
    public Docket docket2() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.oa.controller.user"))
                .paths(PathSelectors.any())
                .build().groupName("emp");
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档")
                .contact(new Contact("OA团队", "https://gitee.com/G318705208/oa", "318705208@qq.com"))
                .version("1.0.0")
                .description("oa项目接口文档")
                .build();
    }
}
